package com.tyk.bookstore.front.auth.controller;


import com.tyk.bookstore.front.auth.model.query.LoginCodeQuery;
import com.tyk.bookstore.front.auth.model.query.LoginPwdQuery;
import com.tyk.bookstore.front.auth.model.query.MsgCodeSendWithBehaviorCheckQuery;
import com.tyk.bookstore.front.auth.service.AuthService;
import com.tyk.bookstore.front.common.core.model.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "认证管理", description = "认证管理")
@RequestMapping({"api/member/auth"})
@RestController
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "发送消息验证码(含行为验证码校验)", description = "发送消息验证码(含行为验证码校验)")
    @PostMapping("code/msg/check-send")
    public R<String> sendMsgCodeWithBehaviorCheck(
            @Validated @RequestBody MsgCodeSendWithBehaviorCheckQuery query
    ) {
        return R.ok(authService.sendMsgCodeWithBehaviorCheck(query));
    }

    @Operation(summary = "密码登录", description = "密码登录")
    @PostMapping("login/pwd")
    public R<String> loginByPwd(
            @Validated @RequestBody LoginPwdQuery query
    ) {
        return R.ok(authService.loginByPwd(query));
    }

    @Operation(summary = "验证码登录", description = "验证码登录")
    @PostMapping("login/code")
    private R<String> loginByCode(
            @Validated @RequestBody LoginCodeQuery query
    ) {
        return R.ok(authService.loginByCode(query));
    }


    @PostMapping({"logout"})
    @Operation(summary = "会员退出", description = "会员退出")
    public R<Object> logout() {
        this.authService.logout();
        return R.ok();
    }
}
